package filter

import (
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 过滤器：股票名称中带“ST”、“*ST”和“退”字的
type StAdnDelistFilter struct {
	db *gorm.DB
}

// 初始化
func (s *StAdnDelistFilter) Init(db *gorm.DB) {
	s.db = db
}

// 执行
func (s *StAdnDelistFilter) DoFilter(transactionDate string) {
	io.Infoln("过滤器：股票名称中带“ST”、“*ST”和“退”字的，交易日期[%s]", transactionDate)

	// 删除股票名称中带“ST”、“*ST”和“退”字的股票
	s.db.Exec("delete quant_stock_filter t2 where t2.stock_code in(" +
		"select t.code_ from stock_info t where t.name_ like '%ST%' or t.name_ like '%退%')")

	//s.db.Exec("delete quant_stock_filter t2 where t2.stock_code not in(" +
	//	"select t.code_ from stock_info t where t.name_ like '%ST%' or t.name_ like '%退%')")

	//s.db.Exec("delete quant_stock_filter t2 where t2.stock_code in("+
	//	"select t.code_ from stock_transaction_data_all t where t.date_=to_date(?,'yyyy-mm-dd') and t.st_or_delist=2)", transactionDate)

}
